-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix a bug that file:read(standard_io, ..)
unexpectedly returns eof
#6881
Conversation
CT Test Results 3 files 142 suites 1h 39m 36s ⏱️ For more details on these failures, see this check. Results for commit 3139ec6. ♻️ This comment has been updated with latest results. To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass. See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally. Artifacts// Erlang/OTP Github Action Bot |
Additional contextI ran into this bug when trying to use erlang_ls with OTP 26-rc1. |
file:read(standard_io, ..)
unexpectedly returns eof
.file:read(standard_io, ..)
unexpectedly returns eof
ea903ec
to
6201bee
Compare
6201bee
to
3139ec6
Compare
Although I tried running the failed test cases on my laptop (m1 macbook pro) as follows, but it succeeded: $ gh repo clone otp
$ cd otp
$ gh pr checkout 6881
$ export ERL_TOP=`pwd`
$ ./otp_build setup -a
$ make stdlib_test ARGS="-suite peer_SUITE"
$ make kernel_test ARGS="-suite global_SUITE" Besides, I created a branch (master-for-stdlib-kernek-ci) from |
Thanks for the PR, and don't sweat the failed testcases, they're a bit unstable on GitHub actions. I've added it to our nightly runs :) |
Merged, thanks again for the PR! |
🎉 |
Various eof scenarios when group is using io_lib:collect_chars was not handled correctly and thus when "oldshell" was changed to be handled by group it broke some existing usages. fixes erlang#7368 fixes erlang#6881 fixes erlang#7286
@garazdawi Thank you for fixing my mistake. But unfortunately, it seems #7384 doesn't solve my original problem. The issue at hand is that the erlang_ls process crashes immediately after attempting to open an Erlang file using Emacs. // Build Erlang/OTP using #7384
$ gh repo clone erlang/otp
$ cd otp
$ gh pr checkout 7384
$ ./configure
$ make
$ sudo make install
$ cd ../
// Build erlang_ls
$ gh repo clone erlang-ls/erlang_ls
$ cd erlang_ls
$ git checkout 0.47.1
$ make
$ sudo make install
// Open an Erlang file (NOTE: you need to have been set up .emacs file to enable erlang_ls when opening Erlang files)
$ emacs /path/to/some-erlang-file.erl
// The erlang_ls process crashes. The following error messages are shown in the *erlang-ls::stderr* Emacs buffer.
[2023-06-09T21:54:35.068498+09:00] [error] Supervisor: {<0.64.0>,user_sup}. Context: child_terminated. Reason: {function_clause,[{group,edit_line,[<<>>,[]],[{file,"group.erl"},{line,888}]},{group,get_line_echo_off,4,[{file,"group.erl"},{line,827}]},{group,get_chars_loop,10,[{file,"group.erl"},{line,502}]},{group,io_request,6,[{file,"group.erl"},{line,190}]},{group,server_loop,3,[{file,"group.erl"},{line,116}]}]}. Offender: pid=<0.69.0>,mod=user_sup. [supervisor_bridge:report_error/3 L152] <0.64.0>
[2023-06-09T21:54:35.068481+09:00] [error] Error in process <0.69.0> with exit value:, {function_clause,[{group,edit_line,[<<>>,[]],[{file,"group.erl"},{line,888}]},{group,get_line_echo_off,4,[{file,"group.erl"},{line,827}]},{group,get_chars_loop,10,[{file,"group.erl"},{line,502}]},{group,io_request,6,[{file,"group.erl"},{line,190}]},{group,server_loop,3,[{file,"group.erl"},{line,116}]}]} [ L] <0.69.0>
[2023-06-09T21:54:35.072422+09:00] [error] Generic server <0.64.0> terminating. Reason: {function_clause,[{group,edit_line,[<<>>,[]],[{file,"group.erl"},{line,888}]},{group,get_line_echo_off,4,[{file,"group.erl"},{line,827}]},{group,get_chars_loop,10,[{file,"group.erl"},{line,502}]},{group,io_request,6,[{file,"group.erl"},{line,190}]},{group,server_loop,3,[{file,"group.erl"},{line,116}]}]}. Last message: {'EXIT',<0.69.0>,{function_clause,[{group,edit_line,[<<>>,[]],[{file,"group.erl"},{line,888}]},{group,get_line_echo_off,4,[{file,"group.erl"},{line,827}]},{group,get_chars_loop,10,[{file,"group.erl"},{line,502}]},{group,io_request,6,[{file,"group.erl"},{line,190}]},{group,server_loop,3,[{file,"group.erl"},{line,116}]}]}}. State: {state,user_sup,undefined,<0.69.0>,{<0.64.0>,user_sup}}. [gen_server:error_info/8 L1373] <0.64.0>
[2023-06-09T21:54:35.072692+09:00] [error] crasher: initial call: supervisor_bridge:user_sup/1, pid: <0.64.0>, registered_name: [], exit: {{function_clause,[{group,edit_line,[<<>>,[]],[{file,"group.erl"},{line,888}]},{group,get_line_echo_off,4,[{file,"group.erl"},{line,827}]},{group,get_chars_loop,10,[{file,"group.erl"},{line,502}]},{group,io_request,6,[{file,"group.erl"},{line,190}]},{group,server_loop,3,[{file,"group.erl"},{line,116}]}]},[{gen_server,handle_common_reply,8,[{file,"gen_server.erl"},{line,1208}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,241}]}]}, ancestors: [kernel_sup,<0.47.0>], message_queue_len: 0, messages: [], links: [<0.49.0>], dictionary: [], trap_exit: true, status: running, heap_size: 6772, stack_size: 28, reductions: 39347; neighbours: [proc_lib:crash_report/4 L584] <0.64.0>
[2023-06-09T21:54:35.072935+09:00] [error] Supervisor: {local,kernel_sup}. Context: child_terminated. Reason: {function_clause,[{group,edit_line,[<<>>,[]],[{file,"group.erl"},{line,888}]},{group,get_line_echo_off,4,[{file,"group.erl"},{line,827}]},{group,get_chars_loop,10,[{file,"group.erl"},{line,502}]},{group,io_request,6,[{file,"group.erl"},{line,190}]},{group,server_loop,3,[{file,"group.erl"},{line,116}]}]}. Offender: id=user,pid=<0.64.0>. [supervisor:do_restart/3 L759] <0.49.0> When I built Erlang/OTP using OTP-26.0 branch, the problem didn't appear. |
What Emacs and OS versions are you using? Could you show the contents of the .emacs file? I followed your steps on Ubuntu using Emacs 27.1 and the config example provided by Erlang-LS and could not reproduce the crash. |
Hmm... My OS and Emacs versions are as follows:
The following is the (require 'package)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
(require 'use-package)
(add-hook 'erlang-mode-hook #'lsp) I'll re-investigate this issue in more detail tomorrow 🙏 |
@garazdawi Let me share another reproduce procedure that directly run 1. Save the first JSON RPC request for LSP with the name
|
Managed to reproduce the error with this example. I did a fix in my PR, can you check if it works for you? |
The latest commit fixed my problem. Thank you! |
Great! |
Various eof scenarios when group is using io_lib:collect_chars was not handled correctly and thus when "oldshell" was changed to be handled by group it broke some existing usages. fixes erlang#7368 fixes erlang#6881 fixes erlang#7286
…/OTP-18640/OTP-18657' into maint * lukas/kernel/fix-reading-characters-from-stdin-maint-26/OTP-18640/OTP-18657: Update primary bootstrap tty: Add cover spec for tty kernel: Make group and prim_tty not get purged by cover kernel: Support sending byte stream on standard in kernel: group:edit_line with echo needs to handle binaries stdlib: Fix eof handling in io_lib:collect_chars Revert "Merge pull request #6881 from sile/fix-escript-binary-stdin-bug"
…/OTP-18640/OTP-18657' into maint-26 * lukas/kernel/fix-reading-characters-from-stdin-maint-26/OTP-18640/OTP-18657: Update primary bootstrap tty: Add cover spec for tty kernel: Make group and prim_tty not get purged by cover kernel: Support sending byte stream on standard in kernel: group:edit_line with echo needs to handle binaries stdlib: Fix eof handling in io_lib:collect_chars Revert "Merge pull request #6881 from sile/fix-escript-binary-stdin-bug" # Conflicts: # bootstrap/lib/kernel/ebin/prim_tty.beam # lib/kernel/src/prim_tty.erl
This PR fixes a bug that
file:read(standard_io, ..)
call in escript could unexpectedly returneof
ifio:setopts(standard_io, [binary])
is set.This bug seems introduced by 72a5fc1 that replaced
user
module bygroup
module.Bug reproduce code
Creates an escript file that calls
file:read/2
twice.Starts Erlang shell and invokes the above escript via
open_port/2
.After
erlang:port_command(P, ["foo"]).
is called, the secondfile:read/2
call in the escript file will return falseyeof
.By applying the change in this PR, the escript behaves as follows: